package com.example.dormmanage.view;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
@ApiModel("返回前端的数据类型")
public class ResultView<T> {

    @ApiModelProperty("状态码")
    private Integer code;

    @ApiModelProperty("数据")
    private T data;

    @ApiModelProperty("提示信息")
    private String msg;

    public static <T>ResultView<T> success(T object){
        ResultView resultView = new ResultView();
        resultView.setCode(200);
        resultView.setData(object);
        resultView.setMsg("操作成功");
        return resultView;
    }

    public static <T>ResultView<T> fail(String msg){
        ResultView resultView = new ResultView();
        resultView.setMsg(msg);
        resultView.setCode(500);
        return resultView;
    }

    public static <T>ResultView<T> fail(String msg,Integer code){
        ResultView resultView = new ResultView();
        resultView.setMsg(msg);
        resultView.setCode(code);
        return resultView;
    }
}
